#include "../tools.h"



class Solution {
public:
    ListNode* deleteNode(ListNode* head, int val) {
        if(head == nullptr) return head;

        ListNode* p = head;
        while(p != nullptr && p->val != val){
            p = p->next;
        }
        if(p != nullptr){
            ListNode* t = p->next;

            p->val = p->next->val;
            p->next = p->next->next;
            delete t; // !
        }
        return head;
    }
};


int main(int argc, char const *argv[])
{
    
    int arr[] = {4,5,1,9};
    int val = 5;
    ListNode* head = create_list(arr, sizeof(arr)/sizeof(int));
    show(head);


    Solution s;
    ListNode* res = s.deleteNode(head, val);
    show(res);

    return 0;
}
